# encoding: utf-8
 
import paho.mqtt.client as mqtt
import time

HOST = "192.168.0.119"
PORT = 1883

def pubMessage(HOST = "192.168.0.119", PORT = 1883, mes=""):
    global sandFlag
    client = mqtt.Client()
    client.connect(HOST, PORT, 60)
    client.loop_start()
    client.publish("test","\nthis is a json{word:1}\n",2) # 发布一个主题为'chat',内容为‘hello liefyuan’的信息
    while True:
        time.sleep(0.1)
        break

def test():
    client = mqtt.Client()
    client.connect(HOST, PORT, 60)
    client.loop_start()

    while True:
        print("发布消息")
        client.publish("test","\nthis is a json{word:1}\n",2) # 发布一个主题为'chat',内容为‘hello liefyuan’的信息
        # 82 09 00 01 00 04 74 65 73 74 00
        # 82 0B 00 01 00 06 73 65 72 76 65 72 00
        time.sleep(2)
    #client.loop_forever()
 
if __name__ == '__main__':
    #test()
    pubMessage()

